﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Collections;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Diagnostics;

//DDI Survey Reader: Lucas Moffitt
//                   LucasMoffitt@Gmail.com
//                   @LucasMoffitt
namespace DDI_Survey_Reader
{
    class ControlFactory
    {

        public ControlFactory()
        {
        
        }

            //Pass in the ControlType, the Width of the Control, and the Control Text.
            public static Control CreateControl(string ControlType, int ItemCounter, params string[] ControlText)
            {
                    try
                    {
                        //Clear off any un needed crap from inputs.
                        for (int TextArrayCounter = 0; TextArrayCounter < ControlText.Length; TextArrayCounter++)
                        {
                           ControlText[TextArrayCounter] = Regex.Replace(ControlText[TextArrayCounter], "{[^}]*}", "");
                        }
                                               
                        Control NewControl;

                        switch(ControlType)
                        {

                            case "Label":
						        NewControl = new Label();
                                ((Label)NewControl).AutoSize = true;
                                NewControl.Name = "lbl_Question" + ItemCounter;
                                NewControl.Text = ControlText[0];
                                break;

                            case "TextBox":
						        NewControl = new TextBox();
                                NewControl.Name = "txt_Answer" + ItemCounter;
                                NewControl.Text = ControlText[0];
                                NewControl.Width = 300;
                                break;

                            case "LargeTextBox":
                                NewControl = new TextBox();
                                ((TextBox)NewControl).ScrollBars = ScrollBars.Vertical;
                                ((TextBox)NewControl).Multiline = true;
                                NewControl.Name = "txt_Answer" + ItemCounter;
                                NewControl.Text = ControlText[0];
                                NewControl.Height = 200;
                                NewControl.Width = 500;
                                break;
                                                                
                            case "ComboBox":
						        NewControl = new ComboBox();
                                ((ComboBox)NewControl).Items.AddRange(ControlText);
                                NewControl.Name = "cmb_Answer" + ItemCounter;
                                NewControl.Text = "Please Select";
                                NewControl.Width = 300;
						        break;

                            case "CheckBox":
						        NewControl = new CheckBox();
                                NewControl.Name = "chk_Answer" + ItemCounter;
                                NewControl.Text = ControlText[0];
                                NewControl.Width = 300;
                                break;

                            default:
                                NewControl = new Label();
                                NewControl.Text = "Error";
                            break;
                                
                        }

                        return NewControl;
                        }

                    catch (Exception ErrorText)
			        {
                        Debug.WriteLine("Couldn't Create Control: " + ErrorText.Message);
                        return new Control();
			        }	
            }
        
        }

    }

